<template>
	<view class="contain">
		<view class="fixed">
			<cu-custom :isBack="false" :color="color" bgColor="bg-shadeTop" @goBack="goBack">
				<block slot="content">
					<!--<view class="content">修改密码</view>-->
					<view class="content">{{lang.modify.modifypassword}}</view>
				</block>
			</cu-custom>
		</view>
		<view class="list">
			<view class="list-box">
				<view class="item">
					<!--<view style="width: 30%;">旧密码</view>-->
					<view style="width: 30%;">{{lang.modify.oldpassword}}</view>
					<!--<input type="password" placeholder="请输入旧密码" v-model="oldPass">-->
					<input type="password" :placeholder="lang.modify.inputoldpassword" v-model="oldPass">
				</view>
				<view class="item">
					<!--<view style="width: 30%;">新密码</view>-->
					<view style="width: 30%;">{{lang.modify.newpassword}}</view>
					<!--<input type="password" placeholder="请输入新密码" v-model="newPass">-->
					<input type="password" :placeholder="lang.modify.inputnewpassword" v-model="newPass">
				</view>
				<view class="item">
					<!--<view style="width: 30%;">确认新密码</view>-->
					<view style="width: 30%;">{{lang.modify.againsurepassword}}</view>
					<!--<input type="password" placeholder="请输入密码" v-model="sureNewPass">-->
					<input type="password" :placeholder="lang.modify.inputpassword" v-model="sureNewPass">
				</view>
			</view>
			<!--<view class="btn1" @tap="goSubmit">提交</view>-->
			<view class="btn1" @tap="goSubmit">{{lang.modify.commit}}</view>
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from "vuex";
	import Toast from '../../common/toast.js'
	export default {
		data() {
			return {
				color: '#333',
				oldPass: '',
				newPass: '',
				sureNewPass: ''
			}
		},
		computed: {
			...mapState(["lang"])
		},
		onLoad() {

		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			goSubmit() {
				const {oldPass,newPass,sureNewPass}=this;
				if(oldPass==''){
					//Toast.showToast('请输入旧密码');
					Toast.showToast(this.lang.modify.inputoldpassword);
					return
				}
				if(newPass==''){
					//Toast.showToast('请输入新密码');
					Toast.showToast(this.lang.modify.inputnewpassword);
					return
				}
				if(sureNewPass==''){
					//Toast.showToast('请再次确认密码');
					Toast.showToast(this.lang.modify.againsurepassword);
					return
				}
				let data1 = {
					oldPassword:oldPass,
					newPassWord:newPass,
					checkNewPassWord:sureNewPass
				}
				this.$u.post('authc/api/user/update_password', data1).then(res => {
					console.log(res)
					if (res.code == 0) {
						uni.setStorageSync('password',data1.newPassWord);
						//Toast.showToast('修改成功！请重新登录')
						Toast.showToast(this.lang.modify.loginagain)
						// #ifdef APP-PLUS
						setTimeout(()=>{
							uni.closeBluetoothAdapter({
								complete() {
									uni.reLaunch({
										url:'/pages/login/login'
									})
								}
							});
						},500)
						// #endif
					}else{
						Toast.showToast(res.resultNote)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contain {
		width: 100%;
		background: #F1F1F1;
		display: flex;
		flex-direction: column;
		align-items: center;

		.fixed {
			width: 100%;

			.content {
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}

		.list {
			width: 100%;
			padding: 0 28rpx;
			box-sizing: border-box;
			margin-top: 30rpx;

			.btn1 {
				width: 80%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 30rpx;
				color: #FFFFFF;
				margin: 120rpx auto 0;
				background: #005883;
				border-radius: 30px;
			}

			.list-box {
				width: 100%;
				border-radius: 6px;
				background: #FFFFFF;

				.item {
					width: 100%;
					padding: 28rpx;
					box-sizing: border-box;
					border-bottom: 1px solid #eee;
					display: flex;
					align-items: center;
					font-size: 28rpx;
					color: #333;
					
					input {
						font-size: 28rpx;
						color: #333;
						margin-left: 50rpx;
					}
				}
			}
		}
	}
</style>
